#ifndef INDEX_CACHE_H_
#define INDEX_CACHE_H_

#include <iostream>
#include <stdlib.h>
#include <string.h>

const int MAXCACHESIZE = 128 * 1024 * 1024; // 128m

class IndexCache {
public:

  explicit IndexCache(int size);
  ~IndexCache();

  bool find(int id, int& len, char* &encode_list);
  bool set(int id, int len, char* encode_list);

private:
  IndexCache();

  struct SNode {
    int id;
    struct SNode* pre;
    struct SNode* next;
  };

  struct IndexStruct {
    int len;
    char* encode_list;
    SNode* pnode;
  };

private:
  int cache_size_;
  int cache_items_;
  int size_;
  SNode* newest_node_;
  SNode* oldest_node_;
  IndexStruct* cache_list_;
};

#endif
